package com.h2cloud.gson;

/**
 * @Package: com.h2cloud.gson
 * @ClassName: Main
 * @Author: wulongkai
 * @CreateTime: 2023/7/21 17:03
 * @Description:
 */

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        Gson gson = new GsonBuilder()
                .registerTypeAdapter(LabelPositionUsed.class, new CustomLabelPositionUsedAdapter())
                .create();

        // 创建LabelPositionUsed对象
        LabelPositionUsed obj = new LabelPositionUsed();
        obj.setLabel("Label 1");
        obj.setValue("4232"); // 设置value字段为字符串"42"
        obj.setIsChange(false);

        // 将对象序列化为JSON字符串
        String json = gson.toJson(obj);
        System.out.println(json);

        // 将JSON字符串反序列化为LabelPositionUsed对象
        LabelPositionUsed deserializedObj = gson.fromJson(json, LabelPositionUsed.class);
        System.out.println(deserializedObj.getValue().getClass()); // 输出反序列化后value字段的类型

        String json2 = "[{\"label\":\"202307\",\"value\":10,\"isChange\":false},{\"label\":\"202308\",\"value\":20,\"isChange\":false},{\"label\":\"202309\",\"value\":30,\"isChange\":false},{\"label\":\"202310\",\"value\":0,\"isChange\":false},{\"label\":\"202311\",\"value\":0,\"isChange\":false},{\"label\":\"202312\",\"value\":0,\"isChange\":false}]";
        List<LabelPositionUsed> labelPositionUseds = gson.fromJson(json2, new TypeToken<List<LabelPositionUsed>>() {
        }.getType());
        System.out.println("labelPositionUseds = " + labelPositionUseds);


        String json3 = "[{\"label\":\"202307\",\"value\":\"0\",\"isChange\":false},{\"label\":\"202308\",\"value\":\"0\",\"isChange\":false},{\"label\":\"202309\",\"value\":\"0\",\"isChange\":false},{\"label\":\"202310\",\"value\":\"0\",\"isChange\":false},{\"label\":\"202311\",\"value\":\"0\",\"isChange\":false},{\"label\":\"202312\",\"value\":\"0\",\"isChange\":false}]";
        List<LabelPositionUsed> labelPositionUseds2 = gson.fromJson(json3, new TypeToken<List<LabelPositionUsed>>() {
        }.getType());
        System.out.println("labelPositionUseds2 = " + labelPositionUseds2);
        
        
        List<Integer> list = new ArrayList<>();
        list.add(1);
        long a = list.stream().filter(e -> e == 2).count();
        System.out.println("a = " + a);

        Integer dkkd = Integer.valueOf("dkkd");
        System.out.println("dkkd = " + dkkd);

    }
}

